<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background: url(https://img.zcool.cn/community/01714a5c5901b1a801203d223f67e1.jpg@1280w_1l_2o_100sh.jpg) no-repeat;
            background-size: cover;
            height: 100vh;
        }

        #canvas {
            margin: auto;
            display: block;
            box-shadow: 0 5px 5px rgba(0, 0, 0, .5);
            background-color: aliceblue;
        }
    </style>
</head>

<body>
    <canvas id="canvas">
    </canvas>
    <script>
        var canvas = document.querySelector("#canvas");
        var WIDTH = 500,
            HEIGHT = 700;

        canvas.width = WIDTH;
        canvas.height = HEIGHT;
        var ctx = canvas.getContext('2d');


        var heartImg = new Image();
        heartImg.src = "./image/心.png";

        var skullImg = new Image();
        skullImg.src = "./image/骷髅.png";

        var HP = 5

        setTimeout(function () {
            for (var i = 0; i < 5; i++) {
                if (i < HP) {
                    ctx.drawImage(heartImg, WIDTH - 50 * (i + 1), 20, 40, 40);
                }else{
                    ctx.drawImage(skullImg, WIDTH - 50 * (i + 1), 20, 40, 40); 
                }
            }
        }, 300)


    </script>
    
</body>

</html>